use crate::error::common::CommonError;
use std::{fs, path::Path};

pub fn create_fold(fold: &String) -> Result<(), CommonError> {
    if !Path::new(fold).exists() {
        fs::create_dir_all(fold)?
    }
    Ok(())
}

pub fn file_exists(path: &String) -> bool {
    return Path::new(path).exists();
}

pub fn read_file(path: &str) -> Result<String, CommonError> {
    if !Path::new(path).exists() {
        return Err(CommonError::CommonError(format!(
            "File {} does not exist",
            path
        )));
    }

    Ok(fs::read_to_string(path)?)
}
